#include "main.h"

int t1,t2,t4;

void InitTim1(void)
{
	TIM1_TimeBaseInit(16, TIM1_COUNTERMODE_UP, 1000, 0);
	TIM1_ARRPreloadConfig(ENABLE);
	TIM1_ITConfig(TIM1_IT_UPDATE, ENABLE);
	TIM1_Cmd(ENABLE);
	t1 = 0;
}

void InitTim2(void)
{
	TIM2_TimeBaseInit(TIM2_PRESCALER_16,1000);
	TIM2_ARRPreloadConfig(ENABLE);
	TIM2_ITConfig(TIM1_IT_UPDATE, ENABLE);
	TIM2_Cmd(ENABLE);
	t2 = 0;
}

void InitTim4(void)  
{  
	TIM4_ARRPreloadConfig(ENABLE);//自动重装
	TIM4_SetCounter(0x00);//计数器初值
	TIM4_SetAutoreload(0xFA);//计数器自动重装的初值
	TIM4_TimeBaseInit(TIM4_PRESCALER_64, 0xff);
  	TIM4_ClearFlag(TIM4_FLAG_UPDATE);
	TIM4_ITConfig(TIM4_IT_UPDATE, ENABLE);
	TIM4_Cmd(ENABLE);
	t4 = 0;
} 


void interrupt1(void)
{
	t1++;
	if (t1==1000){
		if (t1%1==0){
			sensor_check();
			key_scan();
			//key_test();
		}
		GPIO_WriteReverse(GPIOE, LED_STATUS);
		t1 = 0;
	}
	TIM1_ClearITPendingBit(TIM1_IT_UPDATE);
}

void interrupt2(void)
{
	t2++;
	if (t2==1000) {   // 20ms
		//sensor_check();
		t2 = 0;
	}
	TIM2_ClearITPendingBit(TIM2_IT_UPDATE);
}

void interrupt4(void)
{
	t4++;
	if (t4==1000) {
		//GPIO_WriteReverse(GPIOE, LED_STATUS);
		t4 = 0;
	}
	TIM4_ClearITPendingBit(TIM4_IT_UPDATE); //清中断标志位
}
